
// 基础组件 【基础组件】
export const basicComponents = [
  {
    // 组件的自定义配置
    typeId: 'INPUT',
    config: {
      label: '单行文本',
      labelWidth: null,
      showLabel: true,
      changeTag: true,
      tag: 't-input',
      tagIcon: 'input',
      defaultValue: undefined,
      required: true,
      span: 24,
      // 正则校验规则
      regList: [],
      prepend: '',
      append: '',
      // 数据类型
      dataType: {
        type: '',
        message: ''
      }
    },
    // 其余的为可直接写在组件标签上的属性
    placeholder: '请输入',
    style: {width: '100%'},
    clearable: true,
    'prefix-icon': '',
    'suffix-icon': '',
    maxlength: null,
    'show-word-limit': false,
    readonly: false,
    disabled: false
  },
  {
    // 组件的自定义配置
    typeId: 'NUMBER',
    config: {
      label: '数字',
      labelWidth: null,
      showLabel: true,
      changeTag: true,
      tag: 't-number',
      tagIcon: 'number',
      defaultValue: undefined,
      required: true,
      span: 24,
      // 正则校验规则
      regList: []
    },
    // 其余的为可直接写在组件标签上的属性
    placeholder: '请输入',
    style: {width: '100%'},
    min: -Infinity,
    max: Infinity,
    step: 1,
    precision: null,
    disabled: false
  },
  {
    typeId: 'TEXTAREA',
    config: {
      label: '多行文本',
      labelWidth: null,
      showLabel: true,
      tag: 'el-input',
      tagIcon: 'textarea',
      defaultValue: undefined,
      required: true,
      span: 24,
      regList: [],
      changeTag: true
    },
    type: 'textarea',
    placeholder: '请输入',
    autosize: {
      minRows: 4,
      maxRows: 4
    },
    style: {width: '100%'},
    maxlength: null,
    'show-word-limit': false,
    readonly: false,
    disabled: false
  },
  {
    typeId: 'SELECT',
    config: {
      label: '下拉选择',
      showLabel: true,
      labelWidth: null,
      tag: 't-select',
      tagIcon: 'select',
      span: 24,
      required: true,
      regList: [],
      changeTag: true,
      // 0 静态数据  1 动态数据
      optionsType: 0,
      dynamicOptions: {
        url: '',
        dataPath: '',
        valueField: '',
        labelField: ''
      },
      options: [{
        label: '选项一',
        value: 1
      }, {
        label: '选项二',
        value: 2
      }]

    },
    placeholder: '请选择',
    style: {width: '100%'},
    clearable: true,
    disabled: false,
    filterable: false,
    multiple: false
  },
  // {
  //   typeId: 'CASCADER',
  //   config: {
  //     label: '级联选择',
  //     url: '',
  //     method: 'get',
  //     dataKey: 'list',
  //     showLabel: true,
  //     labelWidth: null,
  //     tag: 't-cascader',
  //     tagIcon: 'cascader',
  //     defaultValue: [],
  //     dataType: 'static',
  //     span: 24,
  //     required: true,
  //     regList: [],
  //     changeTag: true,
  //     // 0 静态数据  1 动态数据
  //     optionsType: 0,
  //     dynamicOptions: {
  //       url: '',
  //       dataPath: '',
  //       valueField: '',
  //       labelField: ''
  //     },
  //     options: [{
  //       id: 1,
  //       value: 1,
  //       label: '选项1',
  //       children: [{
  //         id: 2,
  //         value: 2,
  //         label: '选项1-1'
  //       }]
  //     }]
  //   },
  //   placeholder: '请选择',
  //   style: {width: '100%'},
  //   props: {
  //     props: {
  //       multiple: false,
  //       label: 'label',
  //       value: 'value',
  //       children: 'children'
  //     }
  //   },
  //   'show-all-levels': true,
  //   disabled: false,
  //   clearable: true,
  //   filterable: false,
  //   separator: '/'
  // },
  {
    typeId: 'RADIO',
    config: {
      label: '单选框组',
      labelWidth: null,
      showLabel: true,
      showRegList: false,
      tag: 't-radio-group',
      tagIcon: 'radio',
      changeTag: true,
      defaultValue: undefined,
      inline: true,
      span: 24,
      optionType: 'default',
      regList: [],
      required: true,
      border: false,
      // 0 静态数据  1 动态数据
      optionsType: 0,
      dynamicOptions: {
        url: '',
        dataPath: '',
        valueField: '',
        labelField: ''
      },
      options: [{
        label: '选项一',
        value: 1
      }, {
        label: '选项二',
        value: 2
      }]
    },
    style: {},
    size: 'medium',
    disabled: false
  },
  {
    typeId: 'CHECKBOX',
    config: {
      label: '多选框组',
      tag: 't-checkbox-group',
      tagIcon: 'checkbox',
      defaultValue: [],
      span: 24,
      showLabel: true,
      inline: false,
      showRegList: false,
      labelWidth: null,
      optionType: 'default',
      required: true,
      regList: [],
      changeTag: true,
      border: false,
      // 0 静态数据  1 动态数据
      optionsType: 0,
      dynamicOptions: {
        url: '',
        dataPath: '',
        valueField: '',
        labelField: ''
      },
      options: [{
        label: '选项一',
        value: 1
      }, {
        label: '选项二',
        value: 2
      }]
    },
    style: {},
    size: 'medium',
    min: null,
    max: null,
    disabled: false
  },
  {
    typeId: 'DATE',
    config: {
      label: '日期时间',
      tag: 't-date-time',
      tagIcon: 'date',
      defaultNowTime: false,
      defaultValue: null,
      showLabel: true,
      labelWidth: null,
      span: 24,
      required: true,
      regList: [],
      changeTag: true
    },
    placeholder: '请选择',
    type: 'date',
    style: {width: '100%'},
    disabled: false,
    clearable: true,
    format: 'yyyy-MM-dd',
    'value-format': 'yyyy-MM-dd',
    readonly: false
  },
  {
    typeId: 'RATE',
    config: {
      label: '评分',
      tag: 't-rate',
      tagIcon: 'rate',
      defaultValue: 0,
      span: 24,
      showLabel: true,
      showRegList: false,
      labelWidth: null,
      required: true,
      regList: [],
      changeTag: true
    },
    style: {},
    max: 5,
    'allow-half': false,
    'show-text': false,
    'show-score': false,
    disabled: false
  },
  {
    typeId: 'IMAGE',
    config: {
      label: '图片展示',
      showLabel: false,
      displayType: true,
      labelWidth: null,
      showDefaultValue: false,
      showRequired: false,
      showClearable: false,
      showRegList: false,
      tag: 'el-image',
      tagIcon: 'image',
      span: 24,
      required: false,
      regList: [],
      changeTag: true,
      error: 'image'
    },
    style: {width: '100%'},
    src: '',
    fit: 'contain',
    alt: ''
  },
  // {
  //   typeId: 'IMAGE_CAROUSEL',
  //   config: {
  //     label: '图片轮播',
  //     showLabel: false,
  //     displayType: true,
  //     labelWidth: null,
  //     defaultValue: null,
  //     showDefaultValue: false,
  //     showRequired: false,
  //     showClearable: false,
  //     showRegList: false,
  //     tag: 't-image-carousel',
  //     tagIcon: 'image-carousel',
  //     span: 24,
  //     required: false,
  //     regList: [],
  //     changeTag: true,
  //     options: [{
  //       label: '文字',
  //       image: ''
  //     }]
  //   },
  //   style: {width: '100%'}
  // },
  // {
  //   typeId: 'IMAGE_SELECT',
  //   config: {
  //     label: '图片选择',
  //     showLabel: true,
  //     labelWidth: null,
  //     defaultValue: null,
  //     showDefaultValue: true,
  //     showRequired: true,
  //     showClearable: false,
  //     showRegList: false,
  //     tag: 't-image-select',
  //     tagIcon: 'image-select',
  //     span: 24,
  //     required: true,
  //     regList: [],
  //     changeTag: true,
  //     options: [{
  //       label: '选项1',
  //       value: 1
  //     }]
  //   },
  //   multiple: false,
  //   style: {width: '100%'}
  // },
  {
    typeId: 'DESC_TEXT',
    config: {
      label: '文字描述',
      defaultValue: '描述文字',
      displayType: true,
      showDefaultValue: false,
      showRequired: false,
      showClearable: false,
      showRegList: false,
      tag: 'desc-text',
      tagIcon: 'text',
      span: 24,
      required: false,
      regList: [],
      changeTag: false
    },
    content: '描述文字',
    style: {width: '100%'}
  },
  {
    typeId: 'DIVIDER',
    config: {
      label: '分割线',
      defaultValue: '',
      displayType: true,
      showLabel: false,
      showDefaultValue: false,
      showRequired: false,
      showClearable: false,
      showRegList: false,
      tag: 'el-divider',
      tagIcon: 'divider',
      span: 24,
      required: false,
      regList: [],
      changeTag: false
    },
    color: '#000000',
    style: {width: '100%'}
  },
  {
    typeId: 'SLIDER',
    config: {
      label: '滑块',
      tag: 't-slider',
      tagIcon: 'slider',
      defaultValue: 0,
      span: 24,
      showLabel: true,
      showRegList: false,
      labelWidth: null,
      required: true,
      regList: [],
      changeTag: true
    },
    style: {},
    max: 100,
    min: 0,
    step: 1
  },
  // {
  //   typeId: 'SORT',
  //   config: {
  //     label: '排序',
  //     tag: 't-sort',
  //     tagIcon: 'sort',
  //     defaultValue: [],
  //     span: 24,
  //     showLabel: true,
  //     showRegList: false,
  //     labelWidth: null,
  //     required: true,
  //     regList: [],
  //     changeTag: true
  //   },
  //   sortList: [
  //     {
  //       value: 1,
  //       label: '排序1'
  //     },
  //     {
  //       value: 2,
  //       label: '排序2'
  //     }
  //   ],
  //   style: {}
  // }
]

// 高阶组件 【左面板】
export const advancedComponents = [
  {
    typeId: 'UPLOAD',
    config: {
      label: '上传',
      tag: 't-upload',
      tagIcon: 'upload',
      defaultValue: null,
      showLabel: true,
      showRegList: false,
      labelWidth: null,
      required: true,
      span: 24,
      showTip: false,
      buttonText: '点击上传',
      regList: [],
      changeTag: true,
      fileSize: 10,
      sizeUnit: 'MB'
    },
    action: `/form/file/upload/`,
    disabled: false,
    accept: '',
    name: 'file',
    'auto-upload': true,
    'list-type': 'text',
    limit: 2,
    multiple: false
  },
  {
    typeId: 'IMAGE_UPLOAD',
    config: {
      label: '图片上传',
      tag: 't-image-upload',
      tagIcon: 'image-upload',
      defaultValue: [],
      showLabel: true,
      showRegList: false,
      labelWidth: null,
      required: true,
      span: 24,
      showTip: false,
      buttonText: '点击上传',
      regList: [],
      changeTag: true,
      fileSize: 10,
      sizeUnit: 'MB'
    },
    action: `/form/file/upload/`,
    disabled: false,
    accept: 'image/*',
    name: 'file',
    'auto-upload': true,
    limit: 2,
    multiple: false
  },
  {
    typeId: 'SIGN_PAD',
    config: {
      label: '手写签名',
      defaultValue: '',
      showLabel: true,
      showDefaultValue: true,
      showRequired: true,
      showClearable: false,
      showRegList: false,
      tag: 'sign-pad',
      mobileTag: 'mobile-sign-pad',
      tagIcon: 'sign-pad',
      span: 24,
      required: true,
      regList: [],
      changeTag: false
    },
    color: '#000000',
    style: {width: '100%'},
    action: '/form/file/upload/'
  }
]

export const allComponents = [
  {
    title: '基础组件',
    list: basicComponents
  },
  {
    title: '进阶组件',
    list: advancedComponents
  }
]
export default {
  allComponents
}

export let componentsObj = null


export function getComponentsObj() {
  if (!componentsObj) {
    initComponentsObj()
  }
  return componentsObj
}

function initComponentsObj() {
  componentsObj = {}
  allComponents.forEach(comps => {
    comps.list.forEach(item => {
      componentsObj[item.typeId] = item
    })
  })
}
